<?php
/**
 * Created by PhpStorm.
 * User: 睿
 * Date: 2017-11-01
 * Time: 9:33
 */

namespace app\store\controller;

use controller\BasicAdmin;
use service\DataService;
use service\NodeService;
use service\ToolsService;
use think\Db;
use think\View;
use app\mall\model\Store;
use app\index\service\WeixinService;
use think\Config;

class Index extends BasicAdmin
{
    public function _initialize()
    {
        //@lingyun   2018-01-04  一键登入门店
        if(!empty(input('storeid'))){           //门店id
            session('user.store_id',input('storeid'));
        }
        //@lingyun   2018-01-04  一键登入门店
    }

    /**
     * 编辑门店信息
     * @return View
     */
    public function edit()
    {
        //@lingyun   2018-01-04  一键登入门店
        if(!empty(input('storeid'))){           //门店id
            session('user.store_id',input('storeid'));
        }
        //@lingyun   2018-01-04  一键登入门店

        $user = session('user');
        $store = db('store')->where('id',$user['store_id'])->find();
        $this->title = '门店信息 - 余额：￥'.$store['credit'];

        $this->assign([
            'store' => $store,
            'images' => explode('|',$store['images'])
        ]);

        return $this->_form('store', 'edit');
    }

    /**
     * 异步请求
     */
    public function post()
    {
        //域名
        $host = $_SERVER['HTTP_HOST'];
        //地址
        $path = url('add');
        //数据
        $data = [70];
        //异步请求
        post($host, $path, 80, $data);
    }

    /**
     * 异步请求的地址
     */
    public function add()
    {
        $post = input('post.');
        file_put_contents('note.txt', date('m-d H:i:s') . "：成功，数据：".json_encode($post)."\n", FILE_APPEND);
    }

    /**
     * 模板消息
     */
    public function send()
    {
        $wein = new WeixinService();
//        $userinfo = Db::table("ys_user")->where("mobile",$post["mobile"])->find();
        // dd($userinfo["pay_code"].$userinfo["nickname"]);
        // die;
        $array = [
            "type"   	  =>1,
            "touser" 	  =>'oXz3Mv7x6HzyzKKP2tmOOnRXb9Sk',
            "template_id" =>Config::get("mobanid.huiyuan")["tempid"],
            "url" 		  =>Config::get("mobanid.huiyuan")["url"],
            "topcolor"    =>"#743A3A",
            "data"   =>[
                "first" 	    =>["value"=>"恭喜注册成功",        		"color"=>"#743A3A"],
                "keyword1"		=>["value"=>123456, 		            "color"=>"#743A3A"],
                "keyword2"		=>["value"=>'睿力风行', 	            	"color"=>"#743A3A"],
                "keyword3"		=>["value"=>15318889775, 	        	"color"=>"#743A3A"],
                "keyword4"		=>["value"=>date("Y-m-d",time()),       "color"=>"#743A3A"],
                "remark"		=>["value"=>"  感谢您的注册", 			"color"=>"#743A3A"],
            ]
        ];
        $rest  = $wein->sendmsg($array);
    }

    /**
     * @Author  lingyun
     * @Desc    删除图片
     */
    public function del_images(){
        $post = input('post.');
        $res = db('store')->update($post);
//        $this->error('删除失败','');
        $res !==false?$this->success('删除成功',''):$this->error('删除失败','');
    }

}